package com.hdax.dm.controller;

import com.hdax.dm.dto.queryorderlistDto;
import com.hdax.dm.service.queryorderlistService;
import com.hdax.dm.utils.request.tokenutil;
import com.hdax.dm.utils.response.CommonResponse;
import io.jsonwebtoken.Claims;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private queryorderlistService queryorderlistService;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 个人中心订单详情查询
     */
    @PostMapping("p/queryorderlist")
    public CommonResponse<List<queryorderlistDto>> queryorderlist(@RequestBody Map<String,Object> params, HttpServletRequest request){
        Claims claims = tokenutil.parserToken(request.getHeader("token"));
        Integer id = Integer.parseInt(claims.getId()) ;
        return queryorderlistService.queryorderlist(params,id);
    }

//    /**
//     * 添加队列
//     */
//    @GetMapping("add")
//    public String order(@RequestParam("orderNo") String orderNo){
//        rabbitTemplate.convertAndSend("dm_order_exchange","dm.order",orderNo,
//                message -> {
//                    message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT); //持久化
//                    message.getMessageProperties().setExpiration("15000");//过期时间
//                    return message;
//                });
//        return "success";
//    }
}
